<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>添加字典</title>
</head>
<body>
<div id="editDictionaryForm" style="width:630px;">
        <div class="form-Container">
            <form action="${pageContext.request.contextPath}/dictionary/editDictionary.do"  id="dataForm" class="grayForm" method="post">
                <input type="hidden" name="id" value="${param.id }"/>
                <input type="hidden" name="uuid" id="uuid" value=""/>
                <table>
                    <tr>
                        <td ><label for="parentName">上级名称:</label></td>
                        <td colspan="3" style="line-height:20px;">
                          <input type="hidden" id="parentUUID" required name="parentUUID"  value="${param.parentUUID }"/>
                          <input type="text" id="parentName" required name="parentName" style="width:462px;background-color:#F0F0F0" readonly="readonly" value="${param.parentName }"/>
                        </td>
                    </tr>
                    <tr>
                        <td ><label for="dicCode">字典编码:</label></td>
                        <td style="line-height:20px;"><input type="text" id="dicCode" required name="dicCode"  /></td>
                        <td ><label for="dicname">字典名字:</label></td>
                        <td style="line-height:20px;"><input type="text" id="dicname" required name="dicname"  /></td>
                    </tr>
                    <tr>
                        <td><label for="dicdesc">备注:</label></td>
                        <td style="line-height:20px;"><input type="text" name="dicdesc" id="dicdesc"/></td>
                        <td><label for="dicdesc">字典锁:</label></td>
                        <td style="line-height:20px;">
                          <input type="radio" name="locked" id="locked" value="1" checked="checked"/>未锁&nbsp;
                          <input type="radio" name="locked" id="locked" value="0"/><font color=red>锁住</font>&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td><label for="sortid">排序:</label></td>
                        <td colspan="3" style="line-height:20px;"><input type="text" name="sortid" id="sortid"/></td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: center;">
                            <input type="button" value="提交数据" name="submitData"  />
                            <input type="button" value="关闭" name="close" />
                        </td>
                    </tr>
                </table>
                <div id="confirmMsg"></div>
            </form>
        </div>
</div>
        <script type="text/javascript">
        $(document).ready(function () {
        	//判断是父类是否有值，如果无值则赋最高值
        	var parentUUID = $("#parentUUID").val();
        	if(parentUUID==""){
        		$("#parentUUID").val("0");
        		$("#parentName").val("字典根目录");
        	}
        	var baseId = "#editDictionaryForm ";
        	$(baseId+"input[name='close']").click(function () {
       		   $("#editDataFormArea").window("close");
          	})
        	
        	//当改变选项后给companyName赋值
        	$("#editDictionaryForm select[name='companyUUID']").change(function(){
        	    var companyName= $("#editDictionaryForm select[name='companyUUID'] option:selected").text();
        	    $("#editDictionaryForm input[name='companyName']").val(companyName)
        	})
        	
        	var id = new Number($("#editDictionaryForm  input[name='id']").val());
        	var rules = {}
        	var messages = {}
        	messages = {
        			dicCode:"请输入字典编码",
        			dicname:"请输入字典名字"
            };
        	
        	var validateForm = $("#editDictionaryForm #dataForm").validate({
                debug:true,
                rules:rules,
                messages:messages
            });
        	
            //提交数据到服务器
            $("#editDictionaryForm input[name='submitData']").click(function () {
            	//提交表单进行验证
            	$("#editDictionaryForm #dataForm").submit();
                var validateFlag = validateForm.form();
                var actionUrl = $("#editDictionaryForm #dataForm").attr("action");
            	var formData  = $("#editDictionaryForm #dataForm").form2Json();
            	if(validateFlag){
            		$("#editDictionaryForm #dataForm").form('submit',{
            			//当提交时
            			onSubmit:function(param){
            			},
            			success:function(data){
            				// change the JSON string to javascript object 
            				var data = eval('(' + data + ')');
            				if(data.code=="00"){
              				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？',function(flag){
              					  if(flag){
              						// updateCurTab();
              						$("#editDataFormArea").window("close");
              						//window.history.go(0);
              						loadTree();
  		      	        	        loadTableList();
              					  }
              				  });
              			    }else{
              				   $.messager.alert('操作提示',data.message,'error');
              			    }
            			}
            		});
            	}
            });
            
        	if(id>0){
        		//加载表单数据
            	loadFormData(id+"");
        	}
        });
        
        //通过表单加载数据
        function loadFormData(id){
        	$.post(getBasePath()+"/dictionary/getJsonDetail.do",{id:id},function(jsonData){
        		/*
        		for(var jsonKey in jsonData.data){
        			//alert(jsonKey);
        			try{
        				var thisDom = document.getElementById(jsonKey);
            			var domHtml = thisDom.outerHTML;
            			if(domHtml.indexOf("input")>-1){
                			$("input[name='"+jsonKey+"']").val(jsonData.data[jsonKey]);
                		}else if(domHtml.indexOf("select")>-1){
                			$("select[name='"+jsonKey+"']").find("option[value='"+jsonData.data[jsonKey]+"']").attr("selected",true);
                		}else{
                			$("#"+jsonKey+"").val(jsonData.data[jsonKey]);
                		}
        			}catch (e) {
        				
					}
        		}
        		*/
        		$("#editDictionaryForm #dataForm").form("load",jsonData.data);
  		    },"json");
        }
    </script>
</body>
</html>